package com.javaee.controller.user;

import com.javaee.BeforeBaseController;
import com.javaee.entity.User;
import com.javaee.service.user.AuthUserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/userInfo")
public class userInfo extends BeforeBaseController {
    @Autowired
    AuthUserService authUserService;
    @RequestMapping("/toUserInfo")
    public String toUserInfo(HttpSession session, Model model){
        User user = (User)session.getAttribute("User");
        user=authUserService.selectAUser(user.getId());
        session.setAttribute("User",user);
        model.addAttribute("user",user);
        return "user/userInfo";
    }
    @RequestMapping("/toUpdate")
    public String toUpdateUserInfo(HttpSession session, Model model){
        User user = (User)session.getAttribute("User");

        model.addAttribute("user",user);
        return "user/updateUserInfo";
    }
    @RequestMapping("/toRecharge")
    public String toRecharge(HttpSession session, Model model){
        User user = (User)session.getAttribute("User");
        model.addAttribute("user",user);
        return "user/recharge";
    }
    @RequestMapping("/recharge")
    @ResponseBody
    public String recharge(HttpSession session, double money){
        User user = (User)session.getAttribute("User");
        user.setBalance(money+user.getBalance());
        authUserService.updateBalance(user.getId(),user.getBalance());
        session.setAttribute("User",user);
        return "充值成功";
    }

}
